﻿package component.formula.function;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import component.formula.FormulaInfo;
import component.formula.constant.FormulaConstant;
import component.formula.exception.FormulaException;
import component.formula.util.FormulaUtil;

/**
 * 动态列
 */
public class ListHeadType implements IReportType {

	public List parser(List formulaList, Map dataMap) throws FormulaException {
		List parseFormulaList = new ArrayList();
		int colNum = 0;
		for(int i = 0;i<formulaList.size();i++){ 
			String formula = (String)formulaList.get(i);
			FormulaInfo formulaInfo = null;
			if(formula.indexOf('.')==-1){ //不是公式
				formulaInfo = new FormulaInfo();
				formulaInfo.setColNum(colNum);
				parseFormulaList.add(formula);
				Map rowMap = new HashMap();
//				rowMap.put(String.valueOf(formulaInfo.getColNum()), colNum);
//				rowMap.put(FormulaConstant.COMPARE_NAME, String.valueOf(rowMap.get(compareName)));
			}else{//解析公式
				formulaInfo = FormulaUtil.strToFormulObj(formula);
				
				String dsName = formulaInfo.getDsName();
				List dataList = (List) dataMap.get(dsName);
				IReportFunction function = (IReportFunction) FunctionLib.funClassMap.get(formulaInfo.getFunctionName());
				List retList = (List) function.calculate(formulaInfo.getParaExpression(), formulaInfo, dataList);
			}
			colNum++;
		}
		return null;
	}
	
	private static Map getHeadDataMap(){
		Map map = new HashMap();
		
		List dataList = new ArrayList();
		
		Map rowMap = null;
		for(int i = 1;i<3;i++){ // 不能从 0 开始 , 0是根节点
			rowMap = new HashMap();
			rowMap.put("id", "" + i);
			rowMap.put("code", "code" + i);
			rowMap.put("name", "类型" + i);
			rowMap.put("parentId", "-1");
			rowMap.put("order", String.valueOf(i));
			dataList.add(rowMap);
			
			//第二层数据
			for(int j = 100; j<103;j++){
				rowMap = new HashMap();
				rowMap.put("id", i + "_" + j);
				rowMap.put("code", "code" + i + "_" + j);
				rowMap.put("name", "类型" + i + "_"+ j);
				rowMap.put("parentId", "" + i);
				rowMap.put("order", String.valueOf(j));
				dataList.add(rowMap);
				
				//第三层数据
				for(int k = 1005; k>=1000;k--){
					rowMap = new HashMap();
					rowMap.put("id", i + "_" + j + "_" + k);
					rowMap.put("code", "code" + i + "_" + j + "_" + k);
					rowMap.put("name", "类型"  + i + "_" + j + "_" + k);
					rowMap.put("parentId", i + "_" + j);
					rowMap.put("order", String.valueOf(k));
					dataList.add(rowMap);
				}
			}
			
		}
		map.put("ds0", dataList);
		System.out.println("总数：" + dataList.size());
		
		return map;
	}
	
	public static void main(String[] args) {
		List formulaList = new ArrayList();
		formulaList.add("名称");
		formulaList.add("ds0.treeHead(name,id,parentId,-1,order)");
		formulaList.add("备注");
	}

}
